//
//  UICollectionView_refresh.swift
//  MyLibrary
//
//  Created by 周博 on 2020/6/18.
//  Copyright © 2020 ncit. All rights reserved.
//

import UIKit
import MJRefresh

public extension UICollectionView {

    /// 下拉刷新
    func setHeaderRefreshLoadNewData(_ block: @escaping () -> Void) {
        mj_header = MJRefreshNormalHeader(refreshingBlock: {
            block()
        })
        /// 导航栏下隐藏MJ_header
        mj_header!.isAutomaticallyChangeAlpha = true
    }

    /// 上拉加载更多
    func setFooterRefreshLoadMoreData(_ block: @escaping () -> Void) {
        mj_footer = MJRefreshBackNormalFooter(refreshingBlock: {
            block()
        })
    }

    /// 开始 结束 刷新状态
    func endRefresh() {
        mj_header?.endRefreshing()
        mj_footer?.endRefreshing()
    }

    func beginRefreshing() {
        mj_header?.beginRefreshing()
    }

    func endRefreshingWithNoMoreData() {
        mj_footer?.endRefreshingWithNoMoreData()
    }

    func resetNoMoreData() {
        mj_footer?.resetNoMoreData()
    }
}
